import { request } from '@umijs/max';

type ReqLogin = {
  userName: string;
  password: string;
};

/**
 *
 * @param Req 登录
 * @returns
 */
export async function login_api(Req: ReqLogin) {
  return request<ResponseApi.ResUnifyFormat<UserApi.CurrentUser>>('/admin/login/ajaxLogin', {
    method: 'POST',
    data: Req,
  });
}

export async function login_userinfo() {
  return request<ResponseApi.ResUnifyFormat<UserApi.CurrentUser>>('/admin/login/getUser', {
    method: 'GET',
  });
}

export async function login_exit() {
  return request<any>('/admin/login/logout', {
    method: 'GET',
  });
}
export async function edit_paw_api(Req: UserApi.PasswordEdit) {
  return request<ResponseApi.ResUnifyFormat<boolean>>('/admin/login/updetebyPassword', {
    method: 'POST',
    data: Req,
  });
}

// 表单提交
// export async function edit_paw_api(Req: UserApi.PasswordEdit) {
//   return request<ResponseApi.ResUnifyFormat<boolean>>('/admin/login/updetebyPassword', {
//     method: 'POST',
//     headers: {
//       'Content-Type': 'application/x-www-form-urlencoded',
//     },
//     data: Req,
//     transformRequest: [
//       function (data) {
//         // let ret = '';
//         // // eslint-disable-next-line guard-for-in
//         // for (let it in data) {
//         //   ret += encodeURIComponent(it) + '=' + encodeURIComponent(data[it]) + '&';
//         // }
//         // ret = ret.substring(0, ret.lastIndexOf('&'));
//         const ret = new FormData();
//         // eslint-disable-next-line guard-for-in
//         for (const item in data) {
//           ret.append(item, data[item]);
//         }
//         //改成formdata访问
//         return ret;
//       },
//     ],
//   });
// }
